package com.expense.app.admin.controller;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.expense.app.admin.annotation.IgnoreAuth;
import com.expense.app.admin.annotation.LoginUser;
import com.expense.app.admin.annotation.OpeLog;
import com.expense.app.admin.model.params.adminUser.AdminUserModifyPasswordParam;
import com.expense.app.admin.model.params.login.ChangePasswordParam;
import com.expense.app.admin.model.params.login.LoginDetailParam;
import com.expense.app.admin.model.params.login.UserInfoParam;
import com.expense.app.admin.services.LoginServ;
import com.expense.common.model.auth.AdminUser;
import com.expense.common.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/account")
public class LoginCtrl {
    private static final Log log = LogFactory.get();

    @Autowired
    LoginServ loginServ;

    @IgnoreAuth
    @PostMapping("/login")
    public Result findList(@Validated @RequestBody LoginDetailParam param) {
        return Result.success(loginServ.findOne(param));
    }

    @IgnoreAuth
    @GetMapping( "/userinfo")
    public Result getUserInfo(@Validated UserInfoParam param) {
        return Result.success(loginServ.getUserInfo(param));
    }

    @PutMapping("/changePassword")
    @OpeLog(type = "登录用户",value = "修改密码")
    public Result savePassword(@Validated @RequestBody ChangePasswordParam param) {
        loginServ.changePassword(param);
        return Result.success("ok",true);
    }
}
